//
//  HomeCollectionViewCell.m
//  大轮胎
//
//  Created by 朱永超 on 2017/3/23.
//  Copyright © 2017年 zyc. All rights reserved.
//

#import "HomeCollectionViewCell.h"
#import <Masonry.h>
#import <SDWebImage/UIImageView+WebCache.h>
@implementation HomeCollectionViewCell
-(instancetype)initWithFrame:(CGRect)frame
{
    if ([super initWithFrame:frame]) {
        [self.contentView addSubview:self.imageV];
        [self.contentView addSubview:self.titleLbl];
        [self.contentView addSubview:self.nameLbl];
        [self.contentView addSubview:self.borderLabel];
    }
    return self;
}
//传递数据  重写model set
-(void)setCollectionM:(CollectionModel *)collectionM
{
    _collectionM = collectionM;
    
    //图片赋值
    [self.imageV sd_setImageWithURL:[NSURL URLWithString:collectionM.img] placeholderImage:[UIImage imageNamed:@""]];
    //适配
    [self.imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top);
        make.left.mas_equalTo(self.contentView.mas_left);
        make.right.mas_equalTo(self.contentView.mas_right);
        make.height.mas_equalTo(self.contentView.frame.size.width);
    }];
    //标题
    self.titleLbl.text = collectionM.title;
    [self.titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.imageV.mas_bottom).with.offset(5);
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(5);
        make.right.mas_equalTo(self.contentView.mas_right).with.offset(-5);
        make.height.mas_equalTo(15);
    }];
    //名字
    self.nameLbl.text = collectionM.name;
    [self.nameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.titleLbl.mas_bottom);
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(5);
        make.right.mas_equalTo(self.contentView.mas_right).with.offset(-5);
        make.height.mas_equalTo(50);
    }];
    //边框
    [self.borderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top);
        make.left.mas_equalTo(self.contentView.mas_left);
        make.right.mas_equalTo(self.contentView.mas_right);
        make.bottom.mas_equalTo(self.nameLbl.mas_bottom).with.offset(-2);
    }];

}

/**
    图片 @property(nonatomic , strong) UIImageView *imageV;
 */
-(UIImageView *)imageV
{
    if (!_imageV) {
        _imageV = [[UIImageView alloc] init];
        _imageV.contentMode = UIViewContentModeScaleToFill;
        _imageV.layer.borderWidth = 1;
        _imageV.layer.borderColor = [UIColor colorWithRed:180/255.0 green:194/255.0 blue:199/255.0 alpha:1].CGColor;
    }
    return _imageV;
}
/**
    标题 @property(nonatomic , strong) UILabel *titleLbl;
 */
-(UILabel *)titleLbl
{
    if (!_titleLbl) {
        _titleLbl = [[UILabel alloc] init];
        _titleLbl.font = [UIFont systemFontOfSize:16];
        _titleLbl.textColor = [UIColor blackColor];
    }
    return _titleLbl;
}
/**
    商品名字 @property(nonatomic , strong) UILabel *nameLbl;
 */
-(UILabel *)nameLbl
{
    if (!_nameLbl) {
        _nameLbl = [[UILabel alloc] init];
        _nameLbl.font = [UIFont systemFontOfSize:12];
        _nameLbl.textColor = [UIColor grayColor];
        _nameLbl.numberOfLines = 0;
    }
    return _nameLbl;
}
-(UILabel *)borderLabel
{
    if (!_borderLabel) {
        _borderLabel = [[UILabel alloc] init];
        _borderLabel.layer.borderWidth = 0.8;
        _borderLabel.layer.borderColor = [UIColor colorWithRed:180/255.0 green:194/255.0 blue:199/255.0 alpha:1].CGColor;
    }
    return _borderLabel;
}


@end
